using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region PaymentInfo

	/// <summary>
	/// PaymentInfo object for NHibernate mapped table 'PaymentInfo'.
	/// </summary>
	[Serializable]
	public class PaymentInfo : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected int _payer;
		protected bool _isPayServiceProvider;
		protected string _notDirectPayReasons;
		protected decimal _estimatedCustomerTotalCost;
		protected decimal _estimateCustomerdIndividualCost;
		protected string _customerPerdiem;
		protected string _comments;
		protected DicItem _ExpenseType;
		protected Application _application;
		protected IList _costCenterRelatedCosts;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public PaymentInfo() { }

		public PaymentInfo( int payer, bool isPayServiceProvider, string notDirectPayReasons, decimal estimatedCustomerTotalCost, decimal estimateCustomerdIndividualCost, string customerPerdiem, string comments, Application application, DicItem ExpenseType )
		{
			this._payer = payer;
			this._isPayServiceProvider = isPayServiceProvider;
			this._notDirectPayReasons = notDirectPayReasons;
			this._estimatedCustomerTotalCost = estimatedCustomerTotalCost;
			this._estimateCustomerdIndividualCost = estimateCustomerdIndividualCost;
			this._customerPerdiem = customerPerdiem;
			this._comments = comments;
			this._ExpenseType = ExpenseType;
			this._application = application;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public int Payer
		{
			get { return _payer; }
			set { _payer = value; }
		}

		public bool IsPayServiceProvider
		{
			get { return _isPayServiceProvider; }
			set { _isPayServiceProvider = value; }
		}

		public string NotDirectPayReasons
		{
			get { return _notDirectPayReasons; }
			set
			{
				if ( value != null && value.Length > 500)
					value = value.Substring(0, 500 );
				_notDirectPayReasons = value;
			}
		}



		//TODO: encrypt, add by kevin
		public decimal EstimatedCustomerTotalCost
		{
			get { return _estimatedCustomerTotalCost; }
			set { _estimatedCustomerTotalCost = value; }
		}

		public decimal DecryptedEstimatedCustomerTotalCost
		{
			get { return EncryptHelper.Decrypt(_estimatedCustomerTotalCost); }
			set { _estimatedCustomerTotalCost = EncryptHelper.Encrypt(value); }
		}

		//TODO: encrypt, add by kevin
		public decimal EstimateCustomerdIndividualCost
		{
			get { return _estimateCustomerdIndividualCost; }
			set { _estimateCustomerdIndividualCost = value; }
		}

		public decimal DecryptedEstimateCustomerdIndividualCost
		{
			get { return EncryptHelper.Decrypt(_estimateCustomerdIndividualCost); }
			set { _estimateCustomerdIndividualCost = EncryptHelper.Encrypt(value); }
		}

		public string CustomerPerdiem
		{
			get { return _customerPerdiem; }
			set
			{
				if ( value != null && value.Length > 1000)
					value = value.Substring(0, 1000 );
				_customerPerdiem = value;
			}
		}

		public string Comments
		{
			get { return _comments; }
			set
			{
				if ( value != null && value.Length > 250)
					value = value.Substring(0, 250 );
				_comments = value;
			}
		}

		public DicItem ExpenseType
		{
			get { return _ExpenseType; }
			set { _ExpenseType = value; }
		}

		public Application Application
		{
			get { return _application; }
			set { _application = value; }
		}

		public IList CostCenterRelatedCosts
		{
			get
			{
				if (_costCenterRelatedCosts==null)
				{
					_costCenterRelatedCosts = new ArrayList();
				}
				return _costCenterRelatedCosts;
			}
			set { _costCenterRelatedCosts = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is PaymentInfo))
				throw new InvalidCastException("This object is not of type PaymentInfo");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((PaymentInfo)obj).Id);
					break;
				case "Payer":
					relativeValue = this.Payer.CompareTo(((PaymentInfo)obj).Payer);
					break;
				case "IsPayServiceProvider":
					relativeValue = this.IsPayServiceProvider.CompareTo(((PaymentInfo)obj).IsPayServiceProvider);
					break;
				case "NotDirectPayReasons":
						relativeValue = ( this.NotDirectPayReasons != null ) ? this.NotDirectPayReasons.CompareTo(((PaymentInfo)obj).NotDirectPayReasons) : -1;
					break;
				case "EstimatedCustomerTotalCost":
					relativeValue = this.DecryptedEstimatedCustomerTotalCost.CompareTo(((PaymentInfo)obj).DecryptedEstimatedCustomerTotalCost);
					break;
				case "EstimateCustomerdIndividualCost":
					relativeValue = this.DecryptedEstimateCustomerdIndividualCost.CompareTo(((PaymentInfo)obj).DecryptedEstimateCustomerdIndividualCost);
					break;
				case "CustomerPerdiem":
					relativeValue = this.CustomerPerdiem.CompareTo(((PaymentInfo)obj).CustomerPerdiem);
					break;
				case "Comments":
						relativeValue = ( this.Comments != null ) ? this.Comments.CompareTo(((PaymentInfo)obj).Comments) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (PaymentInfo.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
